public class Line extends Figure
{
    public Point point2;

    public Line()
    {
        this(0,0,0,0);
    }

    public Line(Point p1,Point p2)
    {
        super(p1);
        this.point2=new Point(p2);
    }

    public Line(double x1,double y1,double x2,double y2)
    {
        this(new Point(x1,y1),new Point(x2,y2));
    }

    public Line(Line l1)
    {
        this(l1.point1,l1.point2);
    }


//    public String toString()
//    {
//        return "Line{"+
//                "point1="+point1+
//                ", point2="+point2+
//                '}';
//    }

    public String toString()
    {
        return "new Line("+point1+","+point2+")";
    }

    public double length()
    {
        return Math.sqrt((this.point1.getX()-this.point2.getX())*(this.point1.getX()-this.point2.getX())+(this.point1.getY()-this.point2.getY())*(this.point1.getY()-this.point2.getY()));
    }

    public Line revolve(double angle)
    {
        return revolve(new Point(0,0),angle);
    }

    public Line revolve(Point p,double angle)
    {
        return new Line(point1.revolve(p,angle),point2.revolve(p,angle));
    }

    public Line zoom(double percentage)
    {
        return zoom(new Point(0,0),percentage);
    }

    public Line zoom(Point p,double percentage)
    {
        return new Line(point1.zoom(p,percentage),point2.zoom(p,percentage));
    }

    public double getA()
    {
        return this.point2.getY()-this.point1.getY();
    }

    public double getB()
    {
        return this.point1.getX()-this.point2.getX();
    }

    public double getC()
    {
        return this.point2.getX()*this.point1.getY()-this.point1.getX()*this.point2.getY();
    }

    public boolean contains(Point point)
    {
        return MyMath.isEqualDouble(this.distance(point),0);
    }

    public boolean onSegment(Point point)
    {
        return MyMath.isEqualDouble(this.length(),new Line(point1,point).length()+new Line(point,point2).length());
    }

    public Point intersects(Line line)
    {
        double a1=this.getA(), a2=line.getA();
        double b1=this.getB(), b2=line.getB();
        double c1=this.getC(), c2=line.getC();
        double m=a1*b2-a2*b1;
        if(m==0)
            return null;
        return new Point((c2*b1-c1*b2)/m,(c1*a2-c2*a1)/m);
    }

    public double distance(Point p)
    {
        double A=getA();
        double B=getB();
        double C=getC();
        return Math.abs(p.getX()*A+p.getY()*B+C)/Math.sqrt(A*A+B*B);
    }
}
